<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="业务编码" prop="srvSfbillno">
        <el-input
          v-model="queryParams.srvSfbillno"
          placeholder="请输入业务编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来电号码" prop="srvSftel">
        <el-input
          v-model="queryParams.srvSftel"
          placeholder="请输入来电号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="弹单时间" prop="srvSfdate">
        <el-date-picker clearable size="small"
          v-model="queryParams.srvSfdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择弹单时间">
        </el-date-picker>
      </el-form-item>
     
      <el-form-item label="客户姓名" prop="srvSfctmname">
        <el-input
          v-model="queryParams.srvSfctmname"
          placeholder="请输入客户姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="srvSflinktel">
        <el-input
          v-model="queryParams.srvSflinktel"
          placeholder="请输入联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务单来源" prop="srvSfsource">
        <el-input
          v-model="queryParams.srvSfsource"
          placeholder="请输入服务单来源"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标题" prop="srvSftitle">
        <el-input
          v-model="queryParams.srvSftitle"
          placeholder="请输入标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来话性质分类" prop="srvSfprop">
        <el-input
          v-model="queryParams.srvSfprop"
          placeholder="请输入来话性质分类"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来话内容分类" prop="srvSfconttype">
        <el-select v-model="queryParams.srvSfconttype" placeholder="请选择来话内容分类" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:serviceform:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:serviceform:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:serviceform:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:serviceform:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" border :data="serviceformList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="业务编码" align="center" prop="srvSfbillno" width="140" />
      <el-table-column label="来电号码" align="center" prop="srvSftel" width="130" />
      <el-table-column label="弹单时间" align="center" prop="srvSfdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.srvSfdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
  
      <el-table-column label="客户姓名" align="center" prop="srvSfctmname" />
      <el-table-column label="联系电话" align="center" prop="srvSflinktel" width="130"  />
      <el-table-column label="服务单来源" align="center" prop="srvSfsource" width="130"   :formatter="sourceFormat"  />
      <el-table-column label="标题" :show-overflow-tooltip="true" width="190" align="center" prop="srvSftitle" />
      <el-table-column label="主要内容" :show-overflow-tooltip="true" width="250" align="center" prop="srvSfcontent" />
      <el-table-column label="来话性质" align="center" prop="srvSfprop"  :formatter="propFormat"  />
      <el-table-column label="来话内容" align="center" prop="srvSfconttype" width="120"  />
      <el-table-column label="处理方式" align="center" prop="srvSfdealtype" width="130"  :formatter="dealFormat"  />
      <el-table-column label="优先级" align="center" prop="srvSfurgent" :formatter="urgentFormat"  />
      <el-table-column label="保密级别" align="center" prop="srvSfsecret" :formatter="secretFormat" />
      <el-table-column label="是否公布" align="center" prop="srvSfissueflag" />
      <el-table-column label="服务单状态" align="center" prop="srvSfstate" width="120" />
      <el-table-column label="要求办结时间" align="center" prop="srvSfrenddate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.srvSfrenddate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="办结者" align="center" prop="srvSffinisher" />
      <el-table-column label="实际办结时间" align="center" prop="srvSffenddate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.srvSffenddate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="话务员回复" align="center" prop="srvSfanswer"  width="120" />
      <el-table-column label="满意程度" align="center" prop="srvSfsdegree" />
     
      <el-table-column label="创建者" align="center" prop="srvSfoper" />
      <el-table-column label="创建时间" align="center" prop="srvSfopertime" width="140">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.srvSfopertime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后修改者" align="center" prop="srvSflmoper"  width="120" />
      <el-table-column label="最后修改时间" align="center" prop="srvSflmtime" width="140">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.srvSflmtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="srvSfcheck" />
      <el-table-column label="审核者" align="center" prop="srvSfcheckoper" />
      <el-table-column label="审核时间" align="center" prop="srvSfchecktime" width="140">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.srvSfchecktime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    
      <el-table-column label="满意件" align="center" prop="srvSfmanyiflag" />
      <el-table-column label="关注件" align="center" prop="srvSfguanzhuflag" />
    
      <el-table-column label="表单真实号码" align="center" prop="srvSfZhenshiTel" width="130" />
      <el-table-column label="合并件" align="center" prop="srvSfHebing" />
      <el-table-column label="预审状态" align="center" prop="srvYushen" />
      <el-table-column label="再办状态" align="center" prop="srvZaibanflag" />
      <el-table-column label="督办件" align="center" prop="srvSfdubanflag" />

    
      <el-table-column label="操作" align="center" width="130" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:serviceform:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:serviceform:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listServiceform, getServiceform, delServiceform, addServiceform, updateServiceform } from "@/api/system/serviceform";
import Editor from '@/components/Editor';

export default {
  name: "Serviceform",
  components: {
    Editor,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 服务单表格数据
      serviceformList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        srvSfbillno: null,
        srvSftel: null,
        srvSfdate: null,
        crmCtmcode: null,
        srvSfctmname: null,
        srvSflinktel: null,
        srvSfsource: null,
        srvSftitle: null,
        srvSfcontent: null,
        srvSfprop: null,
        srvSfconttype: null,
        orderByColumn:'srvSfdate',
        isAsc:'desc'
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      sourceTypeOptions:[],
      propTypeOptions:[],
      dealTypeOptions:[],
      urgentOptions:[],
      secretOptions:[]
    };
  },
  created() {
    this.getList();
    this.getDicts("Srv_SourceType").then(response => {
      this.sourceTypeOptions = response.data;
    });
    this.getDicts("Srv_PropType").then(response => {
      this.propTypeOptions = response.data;
    });
    this.getDicts("Srv_DealType").then(response => {
      this.dealTypeOptions = response.data;
    });
    this.getDicts("Srv_Urgent").then(response => {
      this.urgentOptions = response.data;
    });
     this.getDicts("Srv_Secret").then(response => {
      this.secretOptions = response.data;
    });
  },
  methods: {
    /** 查询服务单
列表 */
    getList() {
      this.loading = true;
      listServiceform(this.queryParams).then(response => {
        this.serviceformList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    //服务单来源
    sourceFormat(row, column) {
      return this.selectDictLabel(this.sourceTypeOptions, row.srvSfsource);
    },
    //来话性质
    propFormat(row, column) {
      return this.selectDictLabel(this.propTypeOptions, row.srvSfprop);
    },   
    dealFormat (row, column) {
      return this.selectDictLabel(this.dealTypeOptions, row.srvSfdealtype);
    }, 
    urgentFormat(row, column) {
      return this.selectDictLabel(this.urgentOptions, row.srvSfurgent);
    },  
    secretFormat (row, column) {
      return this.selectDictLabel(this.secretOptions, row.srvSfsecret);
    },  
    // 表单重置
    reset() {
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.srvSfcode)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({path:'/service/add'})
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const srvSfcode = row.srvSfcode || this.ids
      getServiceform(srvSfcode).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改服务单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.srvSfcode != null) {
            updateServiceform(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addServiceform(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const srvSfcodes = row.srvSfcode || this.ids;
      this.$confirm('是否确认删除服务单编号为"' + srvSfcodes + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delServiceform(srvSfcodes);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/serviceform/export', {
        ...this.queryParams
      }, `system_serviceform.xlsx`)
    }
  }
};
</script>